{% extends "base.html" %}

{% block content %}
<div class="container mt-4">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h2 class="mb-0">待审批预约</h2>
        <div>
            <a href="{{ url_for('room_status') }}" class="btn btn-outline-primary">
                <i class="bi bi-calendar-check me-2"></i>查看所有预约
            </a>
            <a href="{{ url_for('teacher_logout') }}" class="btn btn-outline-secondary">
                <i class="bi bi-box-arrow-right me-2"></i>退出登录
            </a>
        </div>
    </div>

    <div class="card shadow">
        <div class="card-header">
            当前共有 {{ bookings|length }} 条待审批记录
        </div>
        
        <div class="card-body p-0">
            <div class="table-responsive">
                <table class="table table-hover mb-0">
                    <thead class="table-light">
                        <tr>
                            <th>会议室</th>
                            <th>预约人</th>
                            <th>日期</th>
                            <th>时间段</th>
                            <th>用途</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for booking in bookings %}
                        <tr>
                            <td>{{ booking.room.name }}</td>
                            <td>{{ booking.student_name }} ({{ booking.student_id }})</td>
                            <td>{{ booking.date.strftime('%Y-%m-%d') }}</td>
                            <td>
                                {{ booking.start_time.strftime('%H:%M') }} - 
                                {{ booking.end_time.strftime('%H:%M') }}
                            </td>
                            <td class="text-truncate" style="max-width: 200px;">
                                {{ booking.purpose }}
                            </td>
                            <td>
                                <form action="{{ url_for('approve_booking', booking_id=booking.id) }}" 
                                      method="POST" 
                                      class="d-flex gap-2">
                                    <select name="action" class="form-select form-select-sm">
                                        <option value="approve">同意</option>
                                        <option value="reject">拒绝</option>
                                    </select>
                                    <input type="text" 
                                           name="reason" 
                                           class="form-control form-control-sm" 
                                           placeholder="审批意见"
                                           required>
                                    <button type="submit" class="btn btn-sm btn-primary">
                                        提交
                                    </button>
                                </form>
                            </td>
                        </tr>
                        {% else %}
                        <tr>
                            <td colspan="6" class="text-center py-4">
                                <div class="text-muted">暂无待审批记录</div>
                            </td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
{% endblock %}
